<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 关键字搜索 -->
			<cl-search-key placeholder="搜索标题、内容" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="news-list" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";

const { service } = useCool();

// cl-table
const Table = useTable({
	columns: [
		{
			type: "selection",
			width: 60
		},
		{
			label: "名称",
			prop: "name"
		},
		{
			label: "图片",
			prop: "image",
			component: {
				name: "cl-image",
				props: {
					size: [150, 60]
				}
			}
		},
		{
			label: "排序",
			prop: "index",
			sortable: "desc"
		},
		{
			label: "创建时间",
			prop: "createTime",
			sortable: "desc"
		},
		{
			label: "启用",
			prop: "status",
			width: 100,
			component: {
				name: "cl-switch"
			}
		},
		{
			label: "操作",
			type: "op",
			width: 250,
			buttons: ["info", "edit", "delete"]
		}
	]
});

// cl-upsert
const Upsert = useUpsert({
	dialog: {
		width: "70%"
	},
	items: [
		{
			prop: "name",
			label: "名称",
			component: { name: "el-input" },
			required: true
		},
		{
			prop: "image",
			label: "图片",
			component: { name: "cl-upload", props: { prefixPath: "website", menu: "" } },
			required: true
		},
		{
			prop: "index",
			label: "排序",
			value: 0,
			component: { name: "el-input-number" },
			required: true
		},
		{
			prop: "status",
			label: "状态",
			value: 1,
			component: {
				name: "el-radio-group",
				options: [
					{
						label: "启用",
						value: 1
					},
					{
						label: "禁用",
						value: 0
					}
				]
			}
		}
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.banner.info
	},
	(app) => {
		app.refresh();
	}
);
</script>
